| Total Complexity | 1 |
| Total Lines | 15 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs'; |
||
| 6 | |||
| 7 | @CommandHandler(TryAggregateRootCommand) |
||
| 8 | export class TryAggregateRootCommandHandler implements ICommandHandler<TryAggregateRootCommand> { |
||
| 9 | constructor( |
||
| 10 | @Inject(TRANSPORT_EVENT_BUS_PUBLISHER) private readonly publisher: EventPublisher |
||
| 11 | ) { |
||
| 12 | } |
||
| 13 | |||
| 14 | async execute(command: TryAggregateRootCommand) { |
||
| 15 | const {message} = command; |
||
| 16 | const aggregator = this.publisher.mergeObjectContext( |
||
| 17 | new TestModel() |
||
| 18 | ); |
||
| 19 | aggregator.applyEvent(message); |
||
| 20 | aggregator.commit(); |
||
| 21 | } |
||
| 23 |